<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTableUserSign extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_sign', function (Blueprint $table) {
            $table->id();
            $table->string('key_id',42)->default('')->comment('签到ID yymmdd+user_id');
            $table->integer('user_id')->unsigned()->default(0)->comment('用户ID');
            $table->integer('sign_count')->unsigned()->default(0)->comment('连续签到天数');
            $table->integer('sign_record')->unsigned()->default(0)->comment('签到记录');
            $table->date('last_sign_date')->default('2022-11-01');
            $table->timestamps();
        });
        DB::statement('alter table ex_user_sign comment "用户签到记录表"');
        DB::statement('alter table ex_user_sign add index idx_user_count_date(`user_id`,`sign_count`,`last_sign_date`)');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_sign');
    }
}
